package com.huabo.fxgl.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huabo.fxgl.entity.Riskcategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LiYe
 * @since 2022-08-01
 */
@Repository
public interface RiskcategoryMapper extends BaseMapper<Riskcategory> {
    @Select("select * from tbl_riskcategory t where RISKCATNAME in('企业风险','业务风险','专项风险') ")
    List<Riskcategory> findQYFXByOrgid(QueryWrapper queryWrapper);

    @Select("select RISKCATID from TBL_RISKCATEGORY where 1=1 start with RISKCATID= #{param1} connect by prior RISKCATID= FATHERRISKCATID")
    List<BigDecimal> selectChildCatIds(String parentId);

    @Select("select * from tbl_RiskCategory a start with a.Riskcatid  = #{rootId} connect by prior a.Riskcatid = a.fatherriskcatid")
    List<Riskcategory> findRiskCateByRoot(BigDecimal rootId);

    /**
     * @author wanghongtuo
     * @Date 2022/8/10
     * @Des:根据评估计划查询风险的所属风险分类
     */
    @Select("select DISTINCT r.* from TBL_RISKCATEGORY r where 1=1 start with r.RISKCATID in " +
            "(select RISKCATID from TBL_RISK where RISKID in (select RISKID from TBL_RISK_ASSPLAN_RISK where ASSPLANID = #{asspanid})) " +
            "CONNECT by PRIOR r.FATHERRISKCATID = r.RISKCATID order by riskcatid")
    List<Riskcategory> findRiskCateParentByAssPanid(String asspanid);

}



